﻿using System;
using Moq;
using Myotragus.Data.Containers;
using Myotragus.Data.Repositories;
using Myotragus.Data.Tests.Domain;
using NUnit.Framework;

namespace Myotragus.Data.Tests.Tests.Repository
{
	[TestFixture]
	public class RepositoryFixtures
	{
		[Test]
		public void Start()
		{
			var entities = new Mock<IEntitiesContainer>();

			entities.Setup(m => m.ResolveType(typeof(ITestEntity))).Returns(Type.Missing.GetType());

			var proto = new { T1 = 1, T2 = 2 };
			entities.Setup(m => m.Create(typeof(ITestEntity)));
			entities.Setup(m => m.Create(typeof(ITestEntity), proto));

			var repo = new Repository<ITestEntity>(entities.Object);
			repo.New();
			repo.New(proto);

			Assert.AreEqual(Type.Missing.GetType(), repo.EntityImplementation);

			entities.VerifyAll();
		}

		[Test]
		public void GuardClauses()
		{
			Assert.Throws<ArgumentNullException>(() => new Repository<ITestEntity>(null));

			var entities = new Mock<IEntitiesContainer>();
			var repo = new Repository<ITestEntity>(entities.Object);

			Assert.Throws<ArgumentNullException>(() => repo.New(null));
		}
	}
}